package com.yuexun.dhdoctor.util;




import com.yuexun.dhdoctor.module.contractmanage.bean.HospitalizationRecordBean;
import com.yuexun.dhdoctor.module.contractmanage.bean.OutPatientRecordBean;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;

/**
 * Created by work-jx on 2016/10/31.
 */
public class SortClass implements Comparator {
    @Override
    public int compare(Object o, Object o1) {
        String time = "",time1 = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
        if (o instanceof OutPatientRecordBean.RowsBean) {
            try {
                time = formatter1.format(format.parse(((OutPatientRecordBean.RowsBean) o).getCli_dtime().substring(0,((OutPatientRecordBean.RowsBean) o).getCli_dtime().length()-2)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        else if (o instanceof HospitalizationRecordBean.RowsBean) {
            try {
                time = formatter1.format(format.parse(((HospitalizationRecordBean.RowsBean)o).getInhos_dtime().substring(0,((HospitalizationRecordBean.RowsBean) o).getInhos_dtime().length()-2)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        if (o1 instanceof OutPatientRecordBean.RowsBean) {
            try {
                time1 = formatter1.format(format.parse(((OutPatientRecordBean.RowsBean) o1).getCli_dtime().substring(0,((OutPatientRecordBean.RowsBean) o1).getCli_dtime().length()-2)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        else if (o1 instanceof HospitalizationRecordBean.RowsBean) {
            try {
                time1 = formatter1.format(format.parse(((HospitalizationRecordBean.RowsBean)o1).getInhos_dtime().substring(0,((HospitalizationRecordBean.RowsBean) o1).getInhos_dtime().length()-2)));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        int flag = time.compareTo(time1);
        return flag;
    }
}
